import { useReducer } from 'react';
const getDefauleCity = () => {
    let defaultCity = "武汉"
    if (localStorage.getItem('city')) {
        defaultCity = localStorage.getItem("city")
    }
    return defaultCity;
}
const useMyReducer = () => {
    const initState = {
        city: getDefauleCity()
    }
    // state不要直接修改  需要做一个深拷贝
    const reducer = (state, action) => {
        if (action.type === "changeCity") {
            localStorage.setItem("city", action.value);
            return {
                city: action.value
            }
        }
        return initState
    }
    const [state, dispatch] = useReducer(reducer, initState);
    return { state, dispatch };
}

export default useMyReducer